package utilx

import (
	"crypto/rand"
	"encoding/hex"
	"strconv"

	uuid "github.com/satori/go.uuid"
)

// GenerateRandomID 生成字符串ID
func GenerateRandomID() string {
	b := make([]byte, 32)
	for {
		if _, err := rand.Read(b); err != nil {
			panic(err)
		}
		id := hex.EncodeToString(b)[:12]
		if _, err := strconv.ParseInt(id, 10, 64); err == nil {
			continue
		}
		return id
	}
}

// GenerateUUID 生成全局唯一UUID
func GenerateUUID() string {
	return uuid.NewV4().String()
}
